'''
Created on Nov 27, 2010

@author: philip
'''
from event_service import AddEventRequest,EventService
from django.utils import simplejson
from django.template.loader import render_to_string
from django.http import HttpResponse
from models import Event

def add(request):
    r = request.REQUEST
    aer = AddEventRequest(r["title"], r["description"], 
                          r["place"], r["community"],r["start-date"], 
                          r["end-date"])
    event = EventService().add(aer)
    
    return HttpResponse(simplejson.dumps({"event":event,"html":render_to_string("events/events_renderer.html",{"event":event})},default=Event.toJSON),mimetype="application/json")